package com.ohs.ohsoa.utils.auth;

import java.util.Date;

import com.ohs.ohsoa.system.entity.UserInfo;
import org.springframework.stereotype.Service;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

/***
 * token 下发
 *
 * @Title: TokenService.java
 * @author whf
 * @version V1.0
 */
@Service("TokenService")
public class TokenService {

    public String getToken(UserInfo user) {
        Date start = new Date();
        long currentTime = System.currentTimeMillis() + 60 * 60 * 1000 * 24 * 7;// 7天有效时间
        Date end = new Date(currentTime);
        String token = "";

        token = JWT.create().withAudience(user.getUserinfoGuid()).withIssuedAt(start).withExpiresAt(end)
                .sign(Algorithm.HMAC256(user.getPwd()));
        return token;
    }
}
